/*
 *  Copyright 2010 yura.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package org.opu.doc2db.document.datadocument;

import java.util.Properties;
import java.util.Set;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementMap;

/**
 *  Block (section) of character in text paragraph.
 * Paragraph has styles of present all paragraph, but some
 * part of text selected with specifick properties belonged
 * only for it. In it reason text in paragraph deliminated
 * on text blocks
 * 
 * @author yura
 */
public class TextBlock extends Paragraph {

    /** property of this text block */
    @ElementMap(entry="property", key="key", attribute=true, keyType=String.class, valueType=String.class)
    private Properties properties;

    /** Text in side paragraph */
    @Element(name="value", required=false)
    protected String text;

    /** property font name (monospased, sherif, ...) */
    public static final String PROPERTY_FONT_NAME = "font.name";

    /** property font size (1, 2, ..., 8, 9, ...).
     * <b>Integer properties</b> */
    public static final String PROPERTY_FONT_SIZE = "font.size";

    /** property font style is bold (or strong, or big ...).
     * <b>Boolean properties</b> */
    public static final String PROPERTY_FONT_STYLE_BOLD = "font.style.bold";

    /** property font style is italic (or cursive, ...).
     * <b>Boolean properties</b> */
    public static final String PROPERTY_FONT_STYLE_ITALIC = "font.style.italic";

    /** property font style underline, if text underlined, 
     * it`s value of line width. <b>Integer properties</b> */
    public static final String PROPERTY_FONT_STYLE_UNDERLINE = "font.style.underline";


    /** property color of text in hex presentation, wihout prefix
     * <b>Integer properties</b> */
    public static final String PROPERTY_COLOR = "color";


    /**
     *  Create block without properties and specifick text field
     *
     * @param text text field
     */
    public TextBlock(
//            @Element(name="value")
            String text) {
        this.text = text;
        properties = new Properties();
    }

    /**
     * Create block without properties and empty text field
     */
    public TextBlock() {
        this("");
    }

    /**
     * Get the value of property
     *
     * @return the value of property
     */
    public Properties getProperties() {
        return properties;
    }

    /**
     * Set the value of property
     *
     * @param property new value of property
     */
    public void setProperties(Properties property) {
        this.properties = property;
    }

    /**
     * Get the value of text
     *
     * @return the value of text
     */
    @Override
    public String getText() {
        return text;
    }

    /**
     * Set the value of text
     *
     * @param text new value of text
     */
    public void setText(String text) {
        this.text = text;
    }

    /**
     *  Returns a set of keys of text property
     *
     * @return a set of keys of text property
     */
    public Set<String> stringPropertyNames() {
        return properties.stringPropertyNames();
    }

    /**
     *  Adding new property in to text property list, returning
     * previosly value
     *
     * @param key the key to be placed into text property list.
     * @param value the value corresponding to key.
     * @return the previous value of the specified key in text
     * property list, or null if it did not have one.
     */
    public synchronized Object setProperty(String key, String value) {
        return properties.setProperty(key, value);
    }

    /**
     *  Geting  value of the specified key in text
     * property list, or null if it did not have one.
     * 
     * @param key the key to be placed into text property list.
     * @return value of the specified key in text property
     * list, or null if it did not have one.
     */
    public String getProperty(String key) {
        return properties.getProperty(key);
    }
}
